package com.climber.android.commonres.ui.preview

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
import com.climber.android.commonsdk.util.DragCloseHelper

/**
 * Created by Mikes at 2020-04-17 16:03
 */
class DragFrameLayout @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0)
    : FrameLayout(context, attributeSet, defStyleAttr) {

    private var dragCloseHelper : DragCloseHelper?=null

    fun bindDragHelper(dragCloseHelper : DragCloseHelper){
        this.dragCloseHelper = dragCloseHelper
    }

    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
        return if (dragCloseHelper?.handleEvent(ev) == true) {
            true
        } else {
            super.dispatchTouchEvent(ev)
        }
    }
}